#ifndef _INPUT_
#define _INPUT_

#include "base.h"

#include <list>

using namespace std;

namespace air {

// Trigger Event
#define AIR_KEY_UP			0x0
#define AIR_KEY_DOWN		0x1
#define AIR_KEY_PRESS		0x2
#define AIR_KEY_RELEASE		0x3
#define AIR_MOUSE_UP		0x4
#define AIR_MOUSE_DOWN		0x5
#define AIR_MOUSE_PRESS		0x6
#define AIR_MOUSE_RELEASE	0x7
#define AIR_MOUSE_MOVE_IN	0x8
#define AIR_MOUSE_MOVE_OUT	0x9
#define AIR_MOUSE_MOVE		0xa
#define AIR_IDLE			0xb

/*
** AIR Virtual-key codes
*/

#define AIRK_COUNT		30

#define AIRK_BACKSPACE	0x08
#define AIRK_ESCAPE		0x1B

#define AIRK_A			0x41
#define AIRK_B			0x42
#define AIRK_C			0x43
#define AIRK_D			0x44
#define AIRK_E			0x45
#define AIRK_F			0x46
#define AIRK_G			0x47
#define AIRK_H			0x48
#define AIRK_I			0x49
#define AIRK_J			0x4A
#define AIRK_K			0x4B
#define AIRK_L			0x4C
#define AIRK_M			0x4D
#define AIRK_N			0x4E
#define AIRK_O			0x4F
#define AIRK_P			0x50
#define AIRK_Q			0x51
#define AIRK_R			0x52
#define AIRK_S			0x53
#define AIRK_T			0x54
#define AIRK_U			0x55
#define AIRK_V			0x56
#define AIRK_W			0x57
#define AIRK_X			0x58
#define AIRK_Y			0x59
#define AIRK_Z			0x5A

#define AIRK_0			0x30
#define AIRK_1			0x31
#define AIRK_2			0x32
#define AIRK_3			0x33
#define AIRK_4			0x34
#define AIRK_5			0x35
#define AIRK_6			0x36
#define AIRK_7			0x37
#define AIRK_8			0x38
#define AIRK_9			0x39

#define AIR_LMOUSE		0x70

//TODO mouse

	struct KeyEvent {
		char keyName;
		char state;
		KeyEvent(): state(AIR_KEY_UP) {
		}
	};

	struct KeyState {
		KeyEvent* keys;
		int keyField[AIR_LMOUSE + 1];

		int mouseWheel;
		int leftMouseState;
		bool isMouseMove;
		float x, y;
		int count;
		KeyState(): keys(NULL), count(0), x(0), y(0), isMouseMove(false), leftMouseState(AIR_MOUSE_UP) {
			memset(keyField, 0, sizeof(keyField));
		}

		void assign(const list<char>& keyRecord) {
			delete[] keys;

			count = keyRecord.size();
			keys = new KeyEvent[count];
			int i = 0;
			for (list<char>::const_iterator it = keyRecord.cbegin(); it != keyRecord.cend(); ++it) {
				keys[i++].keyName = *it;
			}
		}

		~KeyState() {
			if (keys) {
				delete[] keys;
			}
		}
	private:
		const KeyState& operator = (const KeyState&);
		KeyState(const KeyState&);
		
	};
}

#endif